pp108 : Download (Library)

Download (Library)

Downloads files from a service or service group running in Cordys.

Syntax

This feature enables you to download file from a service. For instance in Process Platform, the download feature is used for downloading attachments from the Process Platform Inbox.

HTML

<div cordysType="wcp.library.util.Download" id="downloadID" />

where, downloadID is the unique identifier of the component.

Typically in Cordys, all requests from the client are sent to the Process Platform Web Gateway. When the download library is used, the requests are sent to a Java class called Download.wcp (com.eibus.Web.tools.download.Download.wcp), which in turn sends the requests to the Process Platform Web Gateway. This library internally uses an HTML template called download.htm. This template HTML page, along with the values that are set for the properties of the download component, sends a request SOAP message, which is contained in request property, to this Java class.

The value set for the contentType property is taken by the download component and set as the content type of the content that is downloaded from the service.

The value set for the receiver property determines the service, service group, or connect point to which the request is sent. If this property is not set, the gateway sends the request to the first available service group that implements the namespace from the current organization of the user.

The download component takes the response SOAP message from the service and, based on the value set for the searchPath property, searches for the appropriate tag in the SOAP response. It then downloads the content of that tag to the client machine. If the frameId property is set, then the downloaded file will be displayed in that particular IFRAME. If it is not set, the file will be displayed in the page that sent the request.

If an error or SOAP fault occurs while downloading, the ondownloaderror event is fired.

To dynamically add and initialize this component, you can use the initializeHTMLElements or addTypemethods of the Application object.

The properties and methods defined for this component are as follows:

Table 1. List of Attributes

Attribute

Property

Description

contentType

contentType

String that denotes the HTTP content type of the file to be downloaded. By default, this isapplication/octet-stream.

request

request

Object that contains the request SOAP Message that should be sent to theGateway.wcp. The request indicates the XML node from which the download content is to be taken.

timeOut

timeOut

Integer that denotes the time (in milliseconds) that can be taken for the download operation. By default, this is 30000.

organization

organization

String that denotes the organization from which the request is sent. If not mentioned, it takes the default organization of the application.

fileName

fileName

String that denotes the file name to be displayed while opening or saving the file. This property is optional. This property accepts only ASCII characters.

searchPath

searchPath

String that denotes the tag in the SOAP response, the content of which needs to be downloaded.

frameId

N/A

Sets the frameId property, which is a string that denotes the ID of the frame element in which the file can be downloaded. If this is not mentioned, the component downloads the content into the page that sent the request.

receiver

receiver

String that denotes the service, service group, or connection point to which the request is sent. If this is not specified, the request is sent to the first available service group that implements the namespace from the current organization of the user.

openInNewWindow

openInNewWindow

Boolean that determines whether content should be downloaded in a new window or not.When downloading a file, if the target frame is set to Hidden, and if prompt is not enabled for the file type, it will be downloaded in the hidden frame. To avoid this set this property to True.If set to False, the content is downloaded in the same window. This is the default value.
If set to True, the content is downloaded in a new window.

resultHtml

resultHtml

If the user wants to modify the response sent by the Download component, then the user can specify the desired response HTML in the resultHtml property.

Note:
$RESPONSE is the place holder for the upload file response in the given resultHtml.

dispositionType

dispositionType

Content-Disposition information is provided in the dispositionType property. The dispositionType property takes two values:

  • inline
  • attachment

    The default value for dispositionType is 'inline'.

    While sending messages, the user can send it as a single document (inline) or as pieces of information in the form of attachments. That is, the presentation style of the message can be inline or attachments. We need a mechanism to indicate to the recipient this sort of presentational information and the Content-Disposition header provides this mechanism.When this property is set to 'attachment', the browser will always prompt the user with Open or Save dialog box. When this property is not set or when it is set to 'inline', the behavior depends on the browser's default behavior.For items which are not opened in IE (example Excel, PDF and so on), that is, other than HTML, the developer can set this to attachment which will make the browser prompt for open save dialog box. For items which you want to be opened in the browser itself, example HTML, you can set this to inline.
Table 2. List of Methods

Method

Description

downloadFile

Downloads a file from a Web service or SOAP service group.

setFrameId

Sets the frameId property, which is a string that denotes the ID of the frame element in which the file can be downloaded. If this is not mentioned, the component downloads the content into the page that sent the request.

Table 3. List of Events

Event

Description

onbeforedownload

Fires before the files are downloaded.

ondownloaderror

Fires when an error or SOAP fault occurs when downloading.

Note:

  1. Since the files that are stored in various services are generally base64 encoded, the download component assumes that the file to be downloaded is a base64 encoded file, and decodes it before downloading.
  2. Setting the fileName property helps in opening the downloaded file in the registered application associated with that file extension and also makes the File Download Dialog box compulsory. If this property is not set then the File Download Dialog box displays the message downloading com.eibus.tools.download.Download.wcp (as it displays the URL and there is a bug in some versions of the IE where setting of the fileName property has no effect and it displays only the URL). When the user tries to open this , if IE can recognize the file then it will launch the appropriate application. Otherwise, it will open the Choose program window for the user to choose an appropriate program for opening the file. A problem that may be faced here might is that the check box 'Always use this program to open this type of file' is selected then the windows registers that particular program chosen by the user to be used for opening files with '.wcp' extension in the registry. This may cause problems when the user tries to download another file without setting the fileName and contentType property, which may be of a different type.
  3. The Download component can download only one file at a time.

Example

The following example downloads a photo image from the OLE DB service. The sample code assumes that a Method GetPhoto is generated, which will return the photo field for the given EmployeeID. This examples works only in Internet Explorer.

<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'> <head> <script type= text/javascript src="/cordys/wcp/application.js"></script> function getPhoto() { resumeConstruct.selectSingleNode(".//EmployeeID").text = empID.value; downloader.searchPath = "<Photo>"; downloader.organization = "o=Acme,cn=cordys,o=vanenburg.com"; downloader.setFrameId("photoFrame"); downloader.downloadFile(); } </script> </head> <div cordysType="wcp.library.util.Download" id="downloader" request="resumeConstruct.XMLDocument"> <script type ="cordys/xml" id="resumeConstruct"> <SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP:Body> <GetPhoto xmlns="http://schemas.cordys.com/1.0/demo/northwind"> <EmployeeID>PARAMETER</EmployeeID> </GetPhoto> </SOAP:Body> </SOAP:Envelope> </script> </div> <body> <center> <h3>Employees</h3> EmployeeId : <INPUT id="empID" style="width:150px"> <button class="medium" style="width:150px" onclick="getPhoto()"> Download Photo </button> <br><br> <iframe id="photoFrame" style="width:80%;height:60%"></iframe> </body> </html> 

Example

The following code is an example for downloading a file from XMLStore and this will work in all browsers.

<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'> <html> <head> <meta NAME="GENERATOR" Content="Microsoft Visual Studio 6.0" /> <script type="text/javascript" src="/cordys/wcp/application.js"></script> <script type="text/javascript"> function getXmlFile() { var namespaces = {"store":"http://schemas.cordys.com/1.0/xmlstore"} ; downloader.request = resumeConstruct.XMLDocument; cordys.setXMLNamespaces(resumeConstruct.XMLDocument.documentElement.ownerDocument, namespaces); var keyNode = cordys.selectXMLNode(resumeConstruct.XMLDocument,".//store:key", namespaces); cordys.setTextContent(keyNode,document.getElementById("key").value); downloader.searchPath = "<upload>"; downloader.fileName = document.getElementById("key").value; downloader.downloadFile(); } function showError() { alert(cordys.getXML(window.application.event.response)); } </script> <script type="cordys/xml" id="resumeConstruct"> <SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP:Body> <GetXMLObject xmlns="http://schemas.cordys.com/1.0/xmlstore"> <key>PARAMETER</key> </GetXMLObject> </SOAP:Body> </SOAP:Envelope> </script> </head> <body> <div cordysType="wcp.library.util.Download" id="downloader" style="display:none" frameId="myframe2" ondownloaderror="showError()"></div> Key for Xml File :&amp;nbsp;&amp;nbsp;&amp;nbsp;<input id="key" style="WIDTH: 169px; HEIGHT: 22px" size="21" value=""/> <br/><br/><br/> <iframe id="myframe1" name="myframe1" flex="1"></iframe><br /><br /> <iframe id="myframe2" name="myframe2" ></iframe> <center><input type="button" onclick="getXmlFile()" value="Get XmlFile"></input></center> </body> </html>

For more details on using this functionality, refer to Downloading a File from a Service.

Related tasks

Downloading a File from a Service

Related reference

onBeforeDownload
request Property
searchPath Property